package com.example.service.Imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.b_pojo.BAdmin;
import com.example.common.b_pojo.BAdminUser;
import com.example.dao.mapper.BAdminMapper;
import com.example.service.BAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BAdminServiceImp implements BAdminService {

    @Autowired
    private BAdminMapper bAdminMapper;

    @Override
    public Page<BAdminUser> getAlladmin(int pageNum, int pageSize) {
        Page<BAdminUser> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<BAdminUser> queryWrapper = new LambdaQueryWrapper<>();
        return bAdminMapper.selectBAdminAndRoleAndMenuByAdmin(page, queryWrapper);
    }

    @Override
    public int deleteAdmin(int id) {
        return 0;
    }

    @Override
    public int updateAdmin(BAdminUser admin) {
        if (admin != null) {
            UpdateWrapper<BAdmin> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("admin", admin.getAdmin());
            updateWrapper.eq("phone", admin.getPhone());
            updateWrapper.eq("id", admin.getId());
            int i = bAdminMapper.update(admin, updateWrapper);
            return i;
        }
        return 0;
    }

    @Override
    public int updatedeleteAdmin(int id) {
        return 0;
    }

    /**
     * @return boolean
     * @param @param id
     * @author znk
     * @date 2024/8/27 16:46
     * 启用和禁用管理员
     */
    @Override
    public  boolean updateIsdeleteAdmin(Long id) {
        int i = bAdminMapper.updateisdelectByid(id);
        return i>0;
    }


}
